<?php
/**
*	wps文档在线编辑
*/
class wpsChajian extends Chajian{
	public $app_id 	= '';
	public $app_key = '';
	
	
	protected function initChajian()
	{
		$this->app_id 	= getconfig('wpsapp_id');
		$this->app_key 	= getconfig('wpsapp_key');
	}
	
	public function getstype($ext)
	{
		$docx	 = ',doc,dot,wps,wpt,docx,dotx,docm,dotm,';
		$xlsx	 = ',xls,xlt,et,xlsx,xltx,csv,xlsm,xltm,';
		$pptx	 = ',ppt,pptx,pptm,ppsx,ppsm,pps,potx,potm,dpt,dps,';
		$lxw	 = '';
		if(contain($docx,','.$ext.','))$lxw = 'w';
		if(contain($xlsx,','.$ext.','))$lxw = 's';
		if(contain($pptx,','.$ext.','))$lxw = 'p';
		return $lxw;
	}
	
	public function geturl($frs, $sarr=array())
	{
		$lxw	 = $this->getstype($frs['fileext']);
		$arr = array(
			'_w_appid' => $this->app_id,
			'_w_fname' => $frs['filename'],
		);
		foreach($sarr as $k=>$v)$arr[$k] = $v;
		$url = 'https://wwo.wps.cn/office/'.$lxw.'/'.$frs['filenum'].'?';
		$str = '';
		$xu	 = 0;
		ksort($arr);
		foreach($arr as $k=>$v){
			if($xu>0)$url.='&';
			$url.=''.$k.'='.$v.'';
			$str.=''.$k.'='.$v.'';
			$xu++;
		}
		$str.='_w_secretkey='.$this->app_key.'';
		$sign= base64_encode(hash_hmac('sha1',$str, $this->app_key, true));
		$url.='&_w_signature='.urlencode($sign).'';
		
		return $url;
	}
}